package sskj.regulatory.presentation.screen.sitevideo.sitevmain


import android.support.v4.app.Fragment
import com.qmuiteam.qmui.util.QMUIStatusBarHelper

import com.qmuiteam.qmui.widget.QMUITabSegment
import com.vondear.rxtools.RxBarTool
import com.vondear.rxtools.RxTool

import kotlinx.android.synthetic.main.fragment_sitevideo_main.view.*
import sskj.regulatory.R
import sskj.regulatory.presentation.adapter.NormalPagerAdapter
import sskj.regulatory.presentation.base_mvp.base.BaseFragment
import sskj.regulatory.presentation.screen.signature.signedlist.SignedListFragment
import sskj.regulatory.presentation.screen.signature.signedlist.SiteVideoListFragment
import sskj.regulatory.presentation.utils.extensions.addTopMargin
import sskj.regulatory.presentation.utils.extensions.setHeight
import sskj.regulatory.ribble.presentation.utils.extensions.log
import javax.inject.Inject


class SiteVideoMainFragment : BaseFragment<SiteVideoMainContract.View, SiteVideoMainContract.Presenter>(), SiteVideoMainContract.View {

    @Inject
    lateinit var mPresenter: SiteVideoMainPresenter

    private lateinit var mPagerAdapter: NormalPagerAdapter

    private val fragments: ArrayList<Fragment> = ArrayList<Fragment>();

    override fun initPresenter() = mPresenter

    override fun injectDependencies() {
        activityComponent.inject(this)
    }

    override fun onBackPressed(): Boolean = true

    override val layoutResId: Int = R.layout.fragment_sitevideo_main

    override fun initView() {
        initTopBar()
        initTabAndPager()

        val attrsArray = intArrayOf(R.attr.qmui_topbar_height)
        val typedArray = context?.obtainStyledAttributes(attrsArray)
        val height = typedArray?.getDimensionPixelSize(0, 0)
        // mCacheView.svTabSegment.addTopMargin(QMUIStatusBarHelper.getStatusbarHeight(context) + height!!)
        // mCacheView.svCollapsingTopbarLayout.setHeight(QMUIStatusBarHelper.getStatusbarHeight(context) + height!! + 130)
        // mCacheView.svCollapsingTopbarLayout.title = ""
        // mCacheView.svTopBar.addTopMargin(QMUIStatusBarHelper.getStatusbarHeight(context))
        typedArray?.recycle();

    }

    private fun initTabAndPager() {

        fragments.add(SiteVideoListFragment())
        fragments.add(SignedListFragment())
        mPagerAdapter = NormalPagerAdapter(childFragmentManager, fragments)
        mCacheView.svViewPager.adapter = mPagerAdapter
        mCacheView.svViewPager.setNoScroll(true)
        mCacheView.svViewPager.setCurrentItem(0, false)
        mCacheView.svTabSegment.addTab(QMUITabSegment.Tab("监督工程"))
        mCacheView.svTabSegment.addTab(QMUITabSegment.Tab("其它"))
        mCacheView.svTabSegment.setHasIndicator(true)
        mCacheView.svTabSegment.setIndicatorPosition(false)
        mCacheView.svTabSegment.setIndicatorWidthAdjustContent(true)
        mCacheView.svTabSegment.setupWithViewPager(mCacheView.svViewPager, false)
        mCacheView.svTabSegment.mode = QMUITabSegment.MODE_FIXED
        mCacheView.svTabSegment.addOnTabSelectedListener(object : QMUITabSegment.OnTabSelectedListener {

            override fun onTabSelected(index: Int) {

                mCacheView.svTabSegment.hideSignCountView(index)
                mCacheView.svViewPager.setCurrentItem(index, true)

            }

            override fun onTabUnselected(index: Int) {

            }

            override fun onTabReselected(index: Int) {
                mCacheView.svTabSegment.hideSignCountView(index)

            }

            override fun onDoubleTap(index: Int) {

            }
        })

    }

    private fun initTopBar() {

        // ActivityScanerCode.setScanerListener(this);
        mCacheView.svTopBar.setTitle("工地视频")

        mCacheView.svTopBar.addLeftBackImageButton().setOnClickListener { _ ->
            popBackStack()
        }

    }


}